package com.anji.plus.gaea.inf.constant;

import lombok.Getter;

import java.util.stream.Stream;

/**
 * @author weijiaming
 * @since 2021/3/24 10:30
 */
@Getter
public enum ResEnum {

//    FAIL("500", "系统异常", "System error"),
//    INSERT_FAIL("inf_1001", "插入失败", "Insert fail"),
//    AUTHORIZE_APP_FAIL("inf_1002", "授权应用失败", "Authorize app fail"),
//    APP_NOT_EXIST("inf_2001", "应用不存在", "App not exist"),
//    INF_NOT_EXIST("inf_2002", "接口不存在", "Interface not exist"),
//    REQUEST_PARAM_NOT_NULL("inf_2003", "请求参数不能为空", "Request param cannot be empty"),
//    ID_NOT_NULL("inf_2004", "ID不能为空", "Id cannot be empty"),
//    APP_ID_NOT_NULL("inf_2005", "应用ID不能为空", "App id cannot be empty"),
//    APP_NAME_NOT_NULL("inf_2006", "应用名称不能为空", "App name cannot be empty"),
//    INF_NAME_NOT_NULL("inf_2007", "接口名称不能为空", "Interface name cannot be empty"),
//    INF_DESC_NOT_NULL("inf_2008", "接口描述不能为空", "Interface description cannot be empty"),
//    SQL_SEQUENCE_NOT_NULL("inf_2009", "SQL语句不能为空", "Sql sequence cannot be empty"),
//
//    DUPLICATE_APP_ID("inf_3001", "应用ID不能重复", "App id cannot be repeated"),
//    DUPLICATE_INF_NAME("inf_3002", "接口名称不能重复", "Interface name cannot be repeated"),
//    APP_ID_CANNOT_EDIT("inf_3003", "应用ID不能修改", "App id cannot edit"),
//    INF_NAME_CANNOT_EDIT("inf_3004", "接口名称不能修改", "Interface name cannot edit"),
//    SQL_SEQUENCE_ERROR("inf_3005", "SQL语句非法，禁止使用${}填充参数", "Sql error, cannot use ${} fill parameters"),
//    SQL_SEQUENCE_SELECT_ERROR("inf_3006", "查询语句非法", "Select sql error"),
//    PUBLISHED_CANNOT_EDIT("inf_4001", "已上线的接口不能编辑", "The online interface cannot be edited"),
//    PUBLISHED_CANNOT_DELETE("inf_4002", "已上线的接口不能删除", "The online interface cannot delete"),
//    DUPLICATE_PUBLISHED("inf_4003", "已经上线的接口不需要重复上线", "Interface that are already online do not need to be online repeatedly"),
//    ONLY_PASSED_CAN_PUBLISH("inf_4004", "只有测试通过的接口可以上线", "Only the tested interfaces can go online"),
//    ONLY_PUBLISHED_CAN_OFFLINE("inf_4005", "只有已上线的接口才可以下线", "Only the online interface can be offline"),
//    ONLY_PUBLISHED_CAN_EXECUTE("inf_4006", "只有已上线的接口才可以执行，请先上线该接口", "Only the online interface can be executed. Please launch the interface first"),
    APP_SECRET_NOT_NULL("inf_2010", "请求秘钥不能为空", "App secret cannot be empty"),
    SECRET_AUTHENTICATED_FAIL("inf_5001", "秘钥校验失败", "App secret verification failed"),
    JSON_FORMAT_ERROR("inf_5002", "请求参数不是JSON格式", "The request parameter is not in JSON format"),
    EXECUTE_SQL_ERROR("inf_5003", "执行SQL失败,SQL：【{0}】.错误详情：【{1}】", "Execute sql error. SQL：【{0}】.Error detail：【{1}】");

    private String code;
    private String cnMsg;
    private String enMsg;

    ResEnum(String code, String cnMsg, String enMsg) {
        this.code = code;
        this.cnMsg = cnMsg;
        this.enMsg = enMsg;
    }

    public static String getMsg(String code) {
        ResEnum resEnum = Stream.of(values()).filter(value -> value.getCode().equals(code)).findFirst().orElse(null);
        if (resEnum != null) {
            return resEnum.getCnMsg();
        }
        return null;
    }

}
